package com.tfj.mvp.tfj.detail.dongtai;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hyphenate.tfj.R;
import com.jakewharton.rxbinding2.view.RxView;
import com.tfj.comm.bean.Constant;
import com.tfj.mvp.base.BaseActivity;
import com.tfj.mvp.tfj.detail.adapter.QuickAdapter_DongTai;
import com.tfj.mvp.tfj.detail.bean.DongTaiBean;
import com.tfj.mvp.tfj.live.bean.TagBean;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Liang_Lu on 2017/12/21.
 *
 * @author HuangQiang
 * @github https://github.com/HuangQiang
 */

public class VDongTaiActivity extends BaseActivity<PDongTaiImpl> implements CDongTai.IVDongTai {


    @BindView(R.id.recyclew_tag)
    RecyclerView recyclewTag;
    @BindView(R.id.recyclew_content)
    RecyclerView recyclewContent;
    @BindView(R.id.btn_chat)
    Button btnChat;
    @BindView(R.id.btn_tel)
    Button btnTel;
    @Override
    protected void initView() {
        super.initView();
        setTitleText("楼盘动态");
        //标签
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclewTag.setLayoutManager(linearLayoutManager);
        recyclewTag.setAdapter(quickAdapter_tag);
        List<TagBean> beans = new ArrayList<>();
        beans.add(new TagBean("全部"));
        beans.add(new TagBean("楼盘动态"));
        beans.add(new TagBean("楼盘资讯"));
        quickAdapter_tag.replaceData(beans);
        //动态
        QuickAdapter_DongTai quickAdapter_dongTai = new QuickAdapter_DongTai(this);
        LinearLayoutManager linearLayoutManager_dongtai = new LinearLayoutManager(this);
        recyclewContent.setLayoutManager(linearLayoutManager_dongtai);
        recyclewContent.setAdapter(quickAdapter_dongTai);
        List<DongTaiBean> dongTaiBeans = new ArrayList<DongTaiBean>();
        dongTaiBeans.add(new DongTaiBean());
        dongTaiBeans.add(new DongTaiBean());
        dongTaiBeans.add(new DongTaiBean());
        dongTaiBeans.add(new DongTaiBean());
        quickAdapter_dongTai.replaceData(dongTaiBeans);


    }

    @Override
    public int setContentViewId() {
        return R.layout.activity_dongtai;
    }

    @Override
    public void createPresenter() {
        mPresenter = new PDongTaiImpl(mContext, this);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_chat, R.id.btn_tel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_chat:
                break;
            case R.id.btn_tel:
                break;
        }
    }
    private  QuickAdapter_Tag quickAdapter_tag = new QuickAdapter_Tag();
    private int checkPosition = 0;
    public class QuickAdapter_Tag extends BaseQuickAdapter<TagBean, BaseViewHolder> {
        public QuickAdapter_Tag() {
            super(R.layout.item_tag);
        }

        @Override
        protected void convert(BaseViewHolder viewHolder, final TagBean item) {
            RelativeLayout rl_out = viewHolder.getView(R.id.rl_out);
            TextView textView_name = viewHolder.getView(R.id.textView_name);
            textView_name.setText(item.getName());
            textView_name.setTextColor(viewHolder.getPosition() == checkPosition ? Color.parseColor("#ffffff") : Color.parseColor("#ffbfc2cc"));
            rl_out.setBackgroundResource(viewHolder.getPosition() == checkPosition ? R.drawable.shape_background_main_2 : R.drawable.shape_background_gray_2);
            addDisposable(RxView.clicks(rl_out).throttleFirst(Constant.SECONDS_FORBID, TimeUnit.SECONDS)
                    .subscribe(o -> {
                        checkPosition = viewHolder.getPosition();
                        quickAdapter_tag.notifyDataSetChanged();
                    }));
        }
    }
}
